package com.haoma.controller;

import com.haoma.dto.MessageDto;
import com.haoma.result.Result;
import com.haoma.service.MessageService;
import com.haoma.vo.MessageListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Description: 留言管理
 */
@RestController
@RequestMapping("/admin/message")
public class MessageController {


    @Autowired
    private MessageService messageService;

    /**
     * 获取所有的留言信息
     *
     * @return
     */
    @GetMapping("/list")
    public Result getMessageList() {
        Map<String, List> map = messageService.getMessageList();
        return Result.success(map);
    }


    /**
     * 根据名称查询
     *
     * @param name
     * @return
     */
    @GetMapping("/user")
    public Result getMessageUser(String name) {
        return Result.success(messageService.getMessageUser(name));
    }

    /**
     * 根据留言名称查询
     *
     * @param content
     * @return
     */
    @GetMapping("/message")
    public Result getMessage(String content, @RequestParam(required = false) String name) {
        List<MessageListVo> messageListVoList = messageService.getMessage(content, name);
        return Result.success(messageListVoList);
    }

    /**
     * 根据用户查询
     *
     * @param name
     * @return
     */
    @GetMapping("/username")
    public Result getMessageByName(String name) {
        List<MessageListVo> messageListVoList = messageService.getMessageByName(name);
        return Result.success(messageListVoList);
    }

    /**
     * 删除留言信息
     *
     * @return
     */
    @PutMapping("/del/{id}")
    public Result delMessage(@PathVariable Integer id, @RequestBody MessageDto messageDto) {
        messageService.delMessage(id, messageDto);
        return Result.success();
    }

    /**
     * 删除留言用户
     *
     * @param name
     * @return
     */
    @DeleteMapping("/deluser")
    public Result delUser(String name) {
        messageService.delUser(name);
        return Result.success();
    }
}
